﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services;

namespace Xmart.Service
{
    [WebService(Namespace = "http://xmart.net/service")]
    public class ServiceAction : IServiceAction
    {
        [WebMethod(EnableSession = true)]
        public string Execute(string action, string name, params object[] args)
        {
            var context = Spring.Context.Support.ContextRegistry.GetContext();
            var service = context.GetObject<Xmart.Action.IAction>(action);
            
            var ar = service.Execute(name, args);
            return ar.ToString();
        }

        [WebMethod(EnableSession = true)]
        public string ExecuteQuery(string action, string name, string type, params object[] args)
        {
            var context = Spring.Context.Support.ContextRegistry.GetContext();
            var service = context.GetObject<Xmart.Action.IAction>(action);
            var ar = service.ExecuteQuery(name, Spring.Core.TypeResolution.TypeResolutionUtils.ResolveType(type), args);
            return ar.ToString();
        }
    }
}
